package _12_proxy_pattern.v_dynamic_proxy.dynamic_common;

import java.lang.reflect.InvocationHandler;

/**
 * @Description: 场景类
 * @Auther: 2019/6/19 18:32 by zhang.jy
 */
public class Client {
	public static void main(String[] args) {
		//定义一个主题
		Subject subject = new RealSubject();
		//定义一个Handler
		InvocationHandler handler = new MyInvocationHandler(subject);
		//定义主题的代理
		Subject proxy = DynamicProxy.newProxyInstance(subject.getClass().
				getClassLoader(), subject.getClass().getInterfaces(), handler);
		//代理的行为
		proxy.doSomething("Finish");

		//定义一个主题
		Subject subject1 = new RealSubject();
		//定义主题的代理
		Subject proxy1 = SubjectDynamicProxy.newProxyInstance(subject1);
		//代理的行为
		proxy1.doSomething("Finish");
	}
}